﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace ClassLibrary
{
    public class ViewManager<T> where T : UserControl
    {
        private Page m_pageHolder;

        public T LoadViewControl(string path)
        {
            this.m_pageHolder = new Page();
            return (T)this.m_pageHolder.LoadControl(path);
        }

        public string RenderView(T control)
        {
            StringWriter output = new StringWriter();
            HtmlForm form = new HtmlForm();
            form.Controls.Add(control);
            //m_pageHolder.Form = new System.Web.UI.HtmlControls.HtmlForm();
            //m_pageHolder.Form.Controls.Add(control);
            m_pageHolder.Controls.Add(form);
            //this.m_pageHolder.Controls.Add(control);
            
            HttpContext.Current.Server.Execute(m_pageHolder, output, false);
            string html = output.ToString();
            return html;
        }
    }
}
